<template>
  <div class="admin-log-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>后台操作日志</span>
      </div>
      
      <!-- 添加筛选条件 -->
      <div class="filter-container">
        <el-select v-model="selectedAdmin" placeholder="选择管理员" clearable @change="handleFilter">
          <el-option
            v-for="item in adminList"
            :key="item.id"
            :label="item.nickname"
            :value="item.id">
          </el-option>
        </el-select>
      </div>

      <el-table
        :data="logList"
        style="width: 100%"
        border
        v-loading="loading">
        <el-table-column
          prop="id"
          label="ID"
          width="80">
        </el-table-column>
        <el-table-column
          prop="username"
          label="用户名"
          width="120">
        </el-table-column>
        <el-table-column
          prop="ip"
          label="IP地址"
          width="140">
        </el-table-column>
        <el-table-column
          prop="text"
          label="操作内容">
        </el-table-column>
        <el-table-column
          prop="create_time"
          label="操作时间"
          width="180">
        </el-table-column>
      </el-table>

      <div class="pagination-container">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import { getAdminLog , getAdminList } from '@/api/log'
export default {
  name: 'AdminLog',
  data() {
    return {
      logList: [],
      loading: false,
      currentPage: 1,
      pageSize: 10,
      total: 0,
      selectedAdmin: '', // 新增：选中的管理员ID
      adminList: [
       
      ]
    }
  },
  methods: {
    getAdminList() {
        getAdminList({}).then(res => {
            console.log(res)
            this.adminList = res.data
        }) 
    },
    // 获取日志列表数据
    getLogList() {
      this.loading = true
      // 这里替换为实际的API调用
      getAdminLog({
          page: this.currentPage,
          page_size: this.pageSize,
          admin_id: this.selectedAdmin // 添加管理员ID筛选
        }).then(res => {
            console.log()
        this.logList = res.data.data
        this.total = res.data.total
        this.loading = false
      })
    },
    // 新增：处理筛选变化
    handleFilter() {
      this.currentPage = 1 // 重置到第一页
      this.getLogList()
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.getLogList()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.getLogList()
    }
  },
  created() {
    this.getAdminList()
    this.getLogList()
  }
}
</script>

<style scoped>
.admin-log-container {
  padding: 20px;
}
.filter-container {
  margin-bottom: 20px;
}
.pagination-container {
  margin-top: 20px;
  text-align: right;
}
</style>